﻿Imports System.Text.RegularExpressions
Imports System.Collections.ObjectModel
Imports System.Text

Public Class frmTrayPad
    Dim strFileName As String 'SETS THE DESIRED FILENAME FROM THE SAVEAS DIALOG BOX

    Private Sub frmTrayPad_FormClosing(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles Me.FormClosing
        If e.CloseReason <> CloseReason.WindowsShutDown Then
            e.Cancel = True
            Me.Hide()
        End If
    End Sub

    Private Sub tabControl_TabOrderChanged() Handles tabControl.TabOrderChanged
        My.Settings.TabOrder = New ArrayList

        For Each t As cTabPage In tabControl.TabPages
            My.Settings.TabOrder.Add(t.Name)
        Next

        My.Settings.Save()
    End Sub

    Private Sub frmTrayPad_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        'CODE TO CHECK FOR THE CORRESPONDING txt FOR EACH "PAD" AND LOAD IT
        If System.IO.File.Exists(savePath & "pad1.txt") Then
            pad1.Text = System.IO.File.ReadAllText(savePath & "pad1.txt")
        End If
        If System.IO.File.Exists(savePath & "pad2.txt") Then
            pad2.Text = System.IO.File.ReadAllText(savePath & "pad2.txt")
        End If
        If System.IO.File.Exists(savePath & "pad3.txt") Then
            pad3.Text = System.IO.File.ReadAllText(savePath & "pad3.txt")
        End If
        If System.IO.File.Exists(savePath & "pad4.txt") Then
            pad4.Text = System.IO.File.ReadAllText(savePath & "pad4.txt")
        End If
        If System.IO.File.Exists(savePath & "pad5.txt") Then
            pad5.Text = System.IO.File.ReadAllText(savePath & "pad5.txt")
        End If

        If My.Settings.TabOrder IsNot Nothing AndAlso My.Settings.TabOrder.Count > 0 Then
            Dim pages As New Collection(Of cTabPage)
            pages.Add(CType(tabPage1, cTabPage))
            pages.Add(CType(tabPage2, cTabPage))
            pages.Add(CType(tabPage3, cTabPage))
            pages.Add(CType(tabPage4, cTabPage))
            pages.Add(CType(tabPage5, cTabPage))
            tabControl.TabPages.Clear()
            For Each o As Object In My.Settings.TabOrder
                Select Case o.ToString
                    Case "tabPage1"
                        tabControl.TabPages.Add(pages(0))
                    Case "tabPage2"
                        tabControl.TabPages.Add(pages(1))
                    Case "tabPage3"
                        tabControl.TabPages.Add(pages(2))
                    Case "tabPage4"
                        tabControl.TabPages.Add(pages(3))
                    Case "tabPage5"
                        tabControl.TabPages.Add(pages(4))
                End Select
            Next
        End If

        tabPage1.Text = My.Settings.tab1Name
        tabPage2.Text = My.Settings.tab2Name
        tabPage3.Text = My.Settings.tab3Name
        tabPage4.Text = My.Settings.tab4Name
        tabPage5.Text = My.Settings.tab5Name

        'CODE TO FORCE ADD A DATA BINDING FOR padsize AND padlocation
        Me.DataBindings.Add("Size", My.Settings, "padsize", True, DataSourceUpdateMode.OnPropertyChanged)
        Me.DataBindings.Add("Location", My.Settings, "padlocation", True, DataSourceUpdateMode.OnPropertyChanged)

        If My.Settings.npPath <> "" Then
            If Not System.IO.Directory.Exists(My.Settings.npPath) Then
                My.Settings.npPath = Nothing
                My.Settings.Save()
                mnuExportToNP.Enabled = False
                mnuNotePad.Enabled = False
                MessageBox.Show("The path to Notepad++ no longer exists and has been removed.", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
            End If
        End If

        If My.Settings.npPath = "" Then
            mnuExportToNP.Enabled = False
            mnuNotePad.Enabled = False
        End If
        If My.Settings.npLanguage = "" Then
            tscboLanguage.SelectedIndex = 0
        Else
            tscboLanguage.SelectedIndex = tscboLanguage.Items.IndexOf(My.Settings.npLanguage)
        End If
    End Sub

    Private Sub mnutxtRename_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles mnutxtRename.KeyDown
        If e.KeyCode = Keys.Enter Then
            If tabControl.SelectedTab Is tabPage1 Then
                tabPage1.Text = mnutxtRename.Text
                My.Settings.tab1Name = mnutxtRename.Text
            ElseIf tabControl.SelectedTab Is tabPage2 Then
                tabPage2.Text = mnutxtRename.Text
                My.Settings.tab2Name = mnutxtRename.Text
            ElseIf tabControl.SelectedTab Is tabPage3 Then
                tabPage3.Text = mnutxtRename.Text
                My.Settings.tab3Name = mnutxtRename.Text
            ElseIf tabControl.SelectedTab Is tabPage4 Then
                tabPage4.Text = mnutxtRename.Text
                My.Settings.tab4Name = mnutxtRename.Text
            ElseIf tabControl.SelectedTab Is tabPage5 Then
                tabPage5.Text = mnutxtRename.Text
                My.Settings.tab5Name = mnutxtRename.Text
            End If
            My.Settings.Save()
            cmnuTabRename.Hide()
        End If
    End Sub

    Private Sub cmnuTabRename_Closed(ByVal sender As Object, ByVal e As System.Windows.Forms.ToolStripDropDownClosedEventArgs) Handles cmnuTabRename.Closed
        If tabControl.SelectedTab Is tabPage1 Then
            tabPage1.Text = mnutxtRename.Text
            My.Settings.tab1Name = mnutxtRename.Text
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            tabPage2.Text = mnutxtRename.Text
            My.Settings.tab2Name = mnutxtRename.Text
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            tabPage3.Text = mnutxtRename.Text
            My.Settings.tab3Name = mnutxtRename.Text
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            tabPage4.Text = mnutxtRename.Text
            My.Settings.tab4Name = mnutxtRename.Text
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            tabPage5.Text = mnutxtRename.Text
            My.Settings.tab5Name = mnutxtRename.Text
        End If
        My.Settings.Save()
        cmnuTabRename.Hide()
    End Sub

    Private Sub cmnuTabRename_Opened(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmnuTabRename.Opened
        If tabControl.SelectedTab Is tabPage1 Then
            mnutxtRename.Text = tabPage1.Text
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            mnutxtRename.Text = tabPage2.Text
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            mnutxtRename.Text = tabPage3.Text
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            mnutxtRename.Text = tabPage4.Text
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            mnutxtRename.Text = tabPage5.Text
        End If
    End Sub

    Private Sub FileSaveAs()
        Dim saveText As String

        If tabControl.SelectedTab Is tabPage1 Then
            saveText = pad1.Text
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            saveText = pad2.Text
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            saveText = pad3.Text
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            saveText = pad4.Text
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            saveText = pad5.Text
        Else
            saveText = ""
        End If

        System.IO.File.WriteAllText(strFileName, saveText)
    End Sub

    Private Sub TypeWrite() 'FUNCTION FOR SAVING CONTENT OF MULTILINE TEXTBOXES IN EACH TAB
        If tabControl.SelectedTab Is tabPage1 Then
            System.IO.File.WriteAllText(savePath & "pad1.txt", pad1.Text)
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            System.IO.File.WriteAllText(savePath & "pad2.txt", pad2.Text)
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            System.IO.File.WriteAllText(savePath & "pad3.txt", pad3.Text)
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            System.IO.File.WriteAllText(savePath & "pad4.txt", pad4.Text)
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            System.IO.File.WriteAllText(savePath & "pad5.txt", pad5.Text)
        End If
    End Sub

    Private Sub removeTabStop()
        For Each ctrl In Me.Controls
            ctrl.TabStop = False
        Next
    End Sub

    Private Sub returnTabStop()
        For Each ctrl In Me.Controls
            ctrl.TabStop = True
        Next
    End Sub

    Private Sub pad1_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad1.GotFocus
        removeTabStop()
    End Sub

    Private Sub pad1_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pad1.KeyDown
        tslCoord.Text = GetCaretInfo(pad1)
    End Sub

    Private Sub pad1_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad1.LostFocus
        returnTabStop()
    End Sub

    Private Sub pad1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pad1.MouseDown
        tslCoord.Text = GetCaretInfo(pad1)
    End Sub

    Private Sub pad1_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pad1.TextChanged
        TypeWrite()
        tslCoord.Text = GetCaretInfo(pad1)
    End Sub

    Private Sub pad2_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad2.GotFocus
        removeTabStop()
    End Sub

    Private Sub pad2_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pad2.KeyDown
        tslCoord.Text = GetCaretInfo(pad2)
    End Sub

    Private Sub pad2_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad2.LostFocus
        returnTabStop()
    End Sub

    Private Sub pad2_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pad2.MouseDown
        tslCoord.Text = GetCaretInfo(pad2)
    End Sub

    Private Sub pad2_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pad2.TextChanged
        TypeWrite()
        tslCoord.Text = GetCaretInfo(pad2)
    End Sub

    Private Sub pad3_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad3.GotFocus
        removeTabStop()
    End Sub

    Private Sub pad3_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pad3.KeyDown
        tslCoord.Text = GetCaretInfo(pad3)
    End Sub

    Private Sub pad3_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad3.LostFocus
        returnTabStop()
    End Sub

    Private Sub pad3_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pad3.MouseDown
        tslCoord.Text = GetCaretInfo(pad3)
    End Sub

    Private Sub pad3_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pad3.TextChanged
        TypeWrite()
        tslCoord.Text = GetCaretInfo(pad3)
    End Sub

    Private Sub pad4_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad4.GotFocus
        removeTabStop()
    End Sub

    Private Sub pad4_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pad4.KeyDown
        tslCoord.Text = GetCaretInfo(pad4)
    End Sub

    Private Sub pad4_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad4.LostFocus
        returnTabStop()
    End Sub

    Private Sub pad4_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pad4.MouseDown
        tslCoord.Text = GetCaretInfo(pad4)
    End Sub
    Private Sub pad4_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pad4.TextChanged
        TypeWrite()
        tslCoord.Text = GetCaretInfo(pad4)
    End Sub

    Private Sub pad5_GotFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad5.GotFocus
        removeTabStop()
    End Sub

    Private Sub pad5_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles pad5.KeyDown
        tslCoord.Text = GetCaretInfo(pad5)
    End Sub

    Private Sub pad5_LostFocus(ByVal sender As Object, ByVal e As System.EventArgs) Handles pad5.LostFocus
        returnTabStop()
    End Sub

    Private Sub pad5_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles pad5.MouseDown
        tslCoord.Text = GetCaretInfo(pad5)
    End Sub

    Private Sub pad5_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles pad5.TextChanged
        TypeWrite()
        tslCoord.Text = GetCaretInfo(pad5)
    End Sub

    Private Sub PrintDocument1_PrintPage(ByVal sender As System.Object, ByVal e As System.Drawing.Printing.PrintPageEventArgs) Handles PrintDocument1.PrintPage
        Dim rectangleInstance As RectangleF
        rectangleInstance.Width = 785
        rectangleInstance.Height = 1025
        rectangleInstance.X = 30
        rectangleInstance.Y = 30
        Dim printFont As Font = My.Settings.printerfont
        Dim charCount As Integer = 0
        Dim lineCount As Integer = 0

        Static strPrint As String = ""
        Static firstPage As Boolean = True

        If firstPage Then
            If tabControl.SelectedTab Is tabPage1 Then
                strPrint = pad1.Text
            ElseIf tabControl.SelectedTab Is tabPage2 Then
                strPrint = pad2.Text
            ElseIf tabControl.SelectedTab Is tabPage3 Then
                strPrint = pad3.Text
            ElseIf tabControl.SelectedTab Is tabPage4 Then
                strPrint = pad4.Text
            ElseIf tabControl.SelectedTab Is tabPage5 Then
                strPrint = pad5.Text
            End If
            firstPage = False
        End If

        e.Graphics.MeasureString(strPrint, printFont, e.MarginBounds.Size, StringFormat.GenericTypographic, charCount, lineCount)
        e.Graphics.DrawString(strPrint, printFont, Brushes.Black, rectangleInstance)
        strPrint = strPrint.Substring(charCount)

        If strPrint.Length > 0 Then
            e.HasMorePages = True
        Else
            e.HasMorePages = False
            firstPage = True
        End If
    End Sub

    Private Sub mnuFileSaveAs_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileSaveAs.Click
        If SaveAsDialog.ShowDialog = Windows.Forms.DialogResult.OK Then
            strFileName = SaveAsDialog.FileName
            FileSaveAs()
        End If
    End Sub

    Private Sub mnuFilePrint_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFilePrint.Click
        If PrintDialog1.ShowDialog() = DialogResult.OK Then
            PrintDocument1.Print()
        End If
    End Sub

    Private Sub mnuFileExit_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuFileExit.Click
        If MessageBox.Show("Are you sure you want to exit SysPad?", "Confirmation", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) = Windows.Forms.DialogResult.OK Then
            frmSysTray.Close() 'CLOSES FULL PROGRAM
        End If
    End Sub

    Private Sub mnuEdit_MouseEnter(ByVal sender As Object, ByVal e As System.EventArgs) Handles mnuEdit.MouseEnter
        Dim selectedText As String = ""
        If tabControl.SelectedTab Is tabPage1 Then
            selectedText = pad1.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            selectedText = pad2.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            selectedText = pad3.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            selectedText = pad4.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            selectedText = pad5.SelectedText
        Else
            selectedText = ""
        End If

        If selectedText = "" Then
            mnuEditCopy.Enabled = False
            mnuEditCut.Enabled = False
        Else
            mnuEditCopy.Enabled = True
            mnuEditCut.Enabled = True
        End If

        If Clipboard.ContainsText Then
            mnuEditPaste.Enabled = True
        Else
            mnuEditPaste.Enabled = False
        End If
    End Sub

    Private Sub mnuEditCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditCopy.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Copy()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Copy()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Copy()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Copy()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Copy()
        End If
    End Sub

    Private Sub mnuEditCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditCut.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Cut()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Cut()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Cut()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Cut()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Cut()
        End If
    End Sub

    Private Sub mnuEditPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditPaste.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Paste()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Paste()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Paste()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Paste()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Paste()
        End If
    End Sub

    Private Sub mnuEditSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditSelectAll.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.SelectAll()
        End If
    End Sub

    Private Sub mnuEditSettings_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditSettings.Click
        Dim frmSettings As New frmSettings
        frmSettings.ShowDialog()
    End Sub

    Private Sub mnuEditSetPrintFont_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuEditSetPrintFont.Click
        If fdPrinterFont.ShowDialog() = Windows.Forms.DialogResult.OK Then
            My.Settings.printerfont = fdPrinterFont.Font
            My.Settings.Save()
        End If
    End Sub

    Private Sub mnuHelpContents_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpContents.Click
        Process.Start("C:\Program Files\Syspad\syspad_help.chm")
    End Sub

    Private Sub mnuHelpAbout_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHelpAbout.Click
        frmAbout.ShowDialog()
    End Sub

    Private Sub mnuLoadURL_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuLoadURL.Click
        Dim selectedText As String = padRightClick()

        If IsValid_URL_Address(selectedText) Then
            Process.Start(padRightClick())
        End If
    End Sub

    Function padRightClick()
        Dim selectedText As String = ""
        If tabControl.SelectedTab Is tabPage1 Then
            selectedText = pad1.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            selectedText = pad2.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            selectedText = pad3.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            selectedText = pad4.SelectedText
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            selectedText = pad5.SelectedText
        Else
            selectedText = ""
        End If

        If selectedText = "" Then
            mnuCopy.Enabled = False
            mnuCut.Enabled = False
        Else
            mnuCopy.Enabled = True
            mnuCut.Enabled = True
        End If

        If Clipboard.ContainsText Then
            mnuPaste.Enabled = True
        Else
            mnuPaste.Enabled = False
        End If

        If IsValid_URL_Address(selectedText) Then
            mnuLoadURL.Enabled = True
        Else
            mnuLoadURL.Enabled = False
        End If

        Return selectedText
    End Function

    Function IsValid_URL_Address(ByVal sURLAdd As String)
        Return Regex.IsMatch(sURLAdd, "^(http|https|ftp)\://[a-zA-Z0-9\-\.]+\.[a-zA-Z]{2,3}(:[a-zA-Z0-9]*)?/?([a-zA-Z0-9\-\._\?\,\'/\\\+&amp;%\$#\=~])*[^\.\,\)\(\s]$")
    End Function

    Private Sub cmnuTextBox_Opening(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles cmnuTextBox.Opening
        padRightClick()
    End Sub

    Private Sub mnuCopy_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCopy.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Copy()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Copy()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Copy()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Copy()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Copy()
        End If
    End Sub

    Private Sub mnuCut_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuCut.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Cut()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Cut()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Cut()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Cut()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Cut()
        End If
    End Sub

    Private Sub mnuPaste_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuPaste.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.Paste()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.Paste()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.Paste()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.Paste()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.Paste()
        End If
    End Sub

    Private Sub mnuSelectAll_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuSelectAll.Click
        If tabControl.SelectedTab Is tabPage1 Then
            pad1.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            pad2.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            pad3.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            pad4.SelectAll()
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            pad5.SelectAll()
        End If
    End Sub

    Public Function GetCaretInfo(ByRef txt As TextBox) As String
        Return "Line " & (txt.GetLineFromCharIndex(txt.SelectionStart) + 1) & " Col " & (txt.SelectionStart - txt.GetFirstCharIndexOfCurrentLine + 1)
    End Function

    Private Sub mnuNewTab_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNewTab.Click
        mnuNewTab.Checked = True
        mnuNewWindow.Checked = False
    End Sub

    Private Sub mnuNewWindow_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuNewWindow.Click
        mnuNewTab.Checked = False
        mnuNewWindow.Checked = True
    End Sub

    Private Sub mnuExportToNP_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuExportToNP.Click
        Dim npArgs As New StringBuilder("")
        Dim tempPath As String = "C:\WINDOWS\Temp\"
        Dim exportname As String = "new"

        If mnuNewWindow.Checked = True Then
            npArgs.Append("-multiInst ")
        End If
        npArgs.Append("-ro ")
        npArgs.Append("-l" & tscboLanguage.Text & " ")
        npArgs.Append(tempPath)

        If tabControl.SelectedTab Is tabPage1 Then
            System.IO.File.WriteAllText(tempPath & exportname, pad1.Text)
            npArgs.Append(exportname)
        ElseIf tabControl.SelectedTab Is tabPage2 Then
            System.IO.File.WriteAllText(tempPath & exportname, pad2.Text)
            npArgs.Append(exportname)
        ElseIf tabControl.SelectedTab Is tabPage3 Then
            System.IO.File.WriteAllText(tempPath & exportname, pad3.Text)
            npArgs.Append(exportname)
        ElseIf tabControl.SelectedTab Is tabPage4 Then
            System.IO.File.WriteAllText(tempPath & exportname, pad4.Text)
            npArgs.Append(exportname)
        ElseIf tabControl.SelectedTab Is tabPage5 Then
            System.IO.File.WriteAllText(tempPath & exportname, pad5.Text)
            npArgs.Append(exportname)
        End If

        Dim pr As New Process
        pr.StartInfo.FileName = "Notepad++.exe"
        pr.StartInfo.Arguments = npArgs.ToString
        pr.StartInfo.WorkingDirectory = tempPath
        pr.Start()
    End Sub

    Private Sub tscboLanguage_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles tscboLanguage.SelectedIndexChanged
        My.Settings.npLanguage = tscboLanguage.Text
        mnuLanguage.HideDropDown()
        My.Settings.Save()
    End Sub
End Class